<?php

// +----------------------------------------------------------------------
// | Copyright (c) 2015－03－21 http://www.cencn.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 林群伟  <56583965@qq.com> <http://www.xzqly.com>
// +----------------------------------------------------------------------

namespace Admin\Model;

use Think\Model;

/**
 * 产品分类
 */
class AdvModel extends Model {

 /* 自动完成规则 */
    protected $_auto = array(
        array('adv_content', 'serialize', self::MODEL_BOTH, 'function'),
        array('member_id', UID,self::MODEL_INSERT),
        array('adv_start_date', 'strtotime', self::MODEL_BOTH, 'function'),
        array('adv_end_date', 'strtotime', self::MODEL_BOTH, 'function'),
    );
    /**
     * 返回数组
     */
    public function getTree($id,$map) {
        if ($id) {
            $info = $this->info($id);
            $id = $info['id'];
            $map["pid"] = $id;
        }

        $list = $this->where($map)->order('sort desc')->select();
  
        $list = list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_', $root = $id);
   
        /* 获取返回数据 */
        if (isset($info)) { //指定分类则返回当前分类极其子分类
            $info['_'] = $list;
        } else { //否则返回所有分类
            $info = $list;
        }
    
        return $info;
    }

    /**
     * 获取信息
     */
    public function get_goodsclass_info($map) {
        return $this->where($map)->find();
    }

    /**
     * 获取分类
     */
    public function get_goods_class_list($map) {
        return $this->where($map)->select();
    }

}
